import { getRequest, postRequest, putRequest, deleteRequest } from '@/utils/request';
/**
 * 细纱日产量工资表
 * */
export const reportAfterSpinningDayDataNew = (params) => getRequest('/report/after/spinning/day/data/new', params);
export const spinReportAfterPlanGroupYieldCreate = (params) => postRequest('/spinreport/after-plan-group-yield/create', params);
export const spinReportAfterPlanGroupYieldDelete = (params) => deleteRequest('/spinreport/after-plan-group-yield/delete', params);
export const spinReportAfterPlanGroupYieldUpdate = (params) => putRequest('/spinreport/after-plan-group-yield/update', params);
export const spinReportAfterPlanGroupYieldPage = (params) => getRequest('/spinreport/after-plan-group-yield/page', params);
export const spinReportAfterPlanGroupYieldGet = (params) => getRequest('/spinreport/after-plan-group-yield/get', params);

// 给某个员工推送公众号消息
export const wxManageMsgTemplateSendMsgUser = (params) => {
	/**
	 * @params
	 *  {
	 *      openId: xx,
	 *      empName: 张三,
	 *      time: 2023-08-04 晚班/甲班,
	 *      salary: 100,
	 *      qty: 200
	 *
	 *      // 查询条件
	 *      workshopId: 200
	 *      belongDate: 200
	 *      shiftId: 200
	 *      shiftName: 200
	 *      groupId: 200
	 *      groupName: 200
	 *  }
	 * */
	const path = `https://wx.jeacon.cn/#/pages/emp/empGrid/index?workshopId=${params.workshopId}&belongDate=${params.belongDate}&shiftId=${params.shiftId}&shiftName=${params.scheduleShiftName}&groupId=${params.groupId}&groupName=${params.scheduleGroupName}`;
	const payload = {
		'templateId': 'MCXsbdVsimSNrXwRtkdFL6kBTVGboIzCz2ft2numRL0',
		'url': path,
		'appId': 'wx9162addd267014da',
		'openId': params.openId,
		'data': [
			{
				'color': '#000000',
				'name': 'keyword1',
				'value': params.empName
			},
			{
				'color': '#000000',
				'name': 'keyword2',
				'value': params.time
			},
			{
				'color': '#000000',
				'name': 'keyword3',
				'value': `工资: ${params.salary}元 产量: ${params.qty}KG`
			},
			{
				'color': '#000000',
				'name': 'keyword4',
				'value': `机台: ${params.machineList.length}台`
			},
			{
				'color': '#000000',
				'name': 'remark',
				'value': '点击查看详情'
			}
		]
	};
	return postRequest('/wx/msgTemplate/sendMsgUser', payload);
};

// 批量推送到公众号消息
export const msgTemplateSendBatchMsgUser = (params = []) => {
	/**
	 * @params
	 *  {
	 *      openId: xx,
	 *      empName: 张三,
	 *      time: 2023-08-04 晚班/甲班,
	 *      salary: 100,
	 *      qty: 200
	 *
	 *      // 查询条件
	 *      workshopId: 200
	 *      belongDate: 200
	 *      shiftId: 200
	 *      shiftName: 200
	 *      groupId: 200
	 *      groupName: 200
	 *  }
	 * */
	const payload = {
		'appId': 'wx9162addd267014da',
		'msgUserFormList': []
	};
	let path = '';
	params.forEach(x => {
		path = `https://wx.jeacon.cn/#/pages/emp/empGrid/index?workshopId=${x.workshopId}&belongDate=${x.belongDate}&shiftId=${x.shiftId}&shiftName=${x.scheduleShiftName}&groupId=${x.groupId}&groupName=${x.scheduleGroupName}`;
		payload.msgUserFormList.push({
			'url': path,
			'templateId': 'MCXsbdVsimSNrXwRtkdFL6kBTVGboIzCz2ft2numRL0',
			'openId': x.openId,
			'data': [
				{
					'color': '#000000',
					'name': 'keyword1',
					'value': x.empName
				},
				{
					'color': '#000000',
					'name': 'keyword2',
					'value': x.time
				},
				{
					'color': '#000000',
					'name': 'keyword3',
					'value': `工资: ${x.salary}元 产量:${x.qty}KG`
				},
				{
					'color': '#000000',
					'name': 'keyword4',
					'value': `机台: ${x.machineList.length}台`
				},
				{
					'color': '#000000',
					'name': 'remark',
					'value': '点击查看详情'
				}
			]
		});
	});
	return postRequest('/wx/msgTemplate/sendBatchMsgUser', payload);
};

// 推送订单信息给客户推送公众号消息
export const pushOrderToWxUser = (params = []) => {
	/**
	 * @params
	 *  {
	 *      orderCode: MO20230101002,
	 *      productName: 品种,
	 *      batchCode: 批号,
	 *      orderQty: 200,
	 *      completionQty: 22,
	 *      openList: ['xxx'] // openId集合
	 *  }
	 * */
	const payload = {
		'appId': 'wx9162addd267014da',
		'msgUserFormList': []
	};
	params.openList.forEach(x => {
		payload.msgUserFormList.push({
			'url': 'https://wx.jeacon.cn/#/pages/orderList/index',
			'templateId': 'iBbTVV6_W3hM86gQtak-wGK7nttSikUELbMmQHKW9iw',
			'openId': x,
			'data': [
				{
					'color': '#000000',
					'name': 'character_string1',
					'value': params.orderCode
				},
				{
					'color': '#000000',
					'name': 'thing2',
					'value': params.productName
				},
				{
					'color': '#000000',
					'name': 'character_string3',
					'value': params.batchCode
				},
				{
					'color': '#000000',
					'name': 'number4',
					'value': params.completionQty
				},
				{
					'color': '#000000',
					'name': 'phrase5',
					'value': `排产即完工`
				}
			]
		});
	});
	return postRequest('/wx/msgTemplate/sendBatchMsgUser', payload);
};

